/**
 * 统计图表
 * */


//tab
function tabHtml(){
    var tlist = [
        '', '个人', '项目组', '所有项目', '同比环比', //'图形报表',
    ];
    var h = '', i = 1;
    for (; i <= 4; i ++) {
        if (i == type) {
            h += '<div class="tli hover" id="tli0' + i + '" onclick="toTab(' + i + ');">' + tlist[i] + '</div>';
        } else {
            h += '<div class="tli" id="tli0' + i + '" onclick="toTab(' + i + ');">' + tlist[i] + '</div>';
        }
    }
    $('.tab').html(h);
    getList();
}
//图表列表
function getList(){
    var types = [
        '', '个人工时汇总', '项目组工时汇总', '所有项目工时汇总', '同比环比数据比较', //'图形报表',
    ];
    var uinfo = getUserInfo();
    var formData = {
        uid: uinfo.uid, type: type,
    };
    $.ajax({
        type: apiMethod,
        url: apiDomain + 'tongji/index',
        data: formData,
        success: function (res) {
            console.log(res);
            if (res.code != 0) {
                msgPop({msg: res.msg});
                return
            }
            var d = res.data;
            d.tname = types[type];
            if (type != 4) {
                chart(res.data);
            } else {
                chartbi(res.data);
            }
        },
        error: function () {
            console.log('网络错误');
        }
    });
}
function toTab(v){
    window.location.href = 'tongji.html?type=' + v;
}
//个人汇总
function chart(e){
    $('.tlist').highcharts({
        title: {
            text: e.tname,
            x: -20
        },
        subtitle: {
            text: '项目-任务-工时',
            x: -20
        },
        xAxis: {
            categories: e.title
        },
        yAxis: {
            title: {
                text: '时长 (分钟)'
            },
            plotLines: [{
                value: 0,
                width: 1,
                color: '#808080'
            }]
        },
        tooltip: {
            valueSuffix: '分钟'
        },
        legend: {
            layout: 'vertical',
            align: 'right',
            verticalAlign: 'middle',
            borderWidth: 0
        },
        series: [
            {
                name: '项目工时',
                data: e.val
            }
        ]
    });
}
//同比环比
function chartbi(e){
    $('.tlist').highcharts({
        title: {
            text: '同比环比',
            x: -20 //center
        },
        subtitle: {
            text: '项目-任务-工时',
            x: -20
        },
        xAxis: {
            categories: e.title
        },
        yAxis: {
            title: {
                text: '时长 (分钟)'
            },
            plotLines: [{
                value: 0,
                width: 1,
                color: '#808080'
            }]
        },
        tooltip: {
            valueSuffix: '°C'
        },
        legend: {
            layout: 'vertical',
            align: 'right',
            verticalAlign: 'middle',
            borderWidth: 0
        },
        series: [
            {
                name: '上一个5天',
                data: e.valPre
            }
            , {
                name: '最近5天',
                data: e.val
            }
        ]
    });
}